<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('个人答题详情')" />
    <style>
        .detail-card {
            margin-bottom: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
            transition: all 0.3s ease;
        }
        .detail-card:hover {
            box-shadow: 0 4px 20px 0 rgba(0, 0, 0, 0.15);
            transform: translateY(-2px);
        }
        .detail-card .card-header {
            padding: 15px 20px;
            border-bottom: 1px solid #e8e8e8;
            font-weight: bold;
        }
        .detail-card .card-body {
            padding: 20px;
        }
        .question-item {
            padding: 15px 0;
            border-bottom: 1px solid #f0f0f0;
        }
        .question-item:last-child {
            border-bottom: none;
        }
        .question-title {
            font-size: 16px;
            font-weight: bold;
            margin-bottom: 10px;
            color: #333;
        }
        .question-options {
            margin: 10px 0;
        }
        .option-item {
            padding: 5px 10px;
            margin: 5px 0;
            border-radius: 4px;
        }
        .option-item.selected {
            background-color: #e6f7ff;
            border: 1px solid #1890ff;
        }
        .option-item.correct {
            background-color: #f6ffed;
            border: 1px solid #52c41a;
        }
        .user-answer {
            margin: 10px 0;
            padding: 8px;
            background-color: #e6f7ff;
            border-left: 3px solid #1890ff;
            border-radius: 4px;
        }
        .correct-answer {
            margin: 10px 0;
            padding: 8px;
            background-color: #f6ffed;
            border-left: 3px solid #52c41a;
            border-radius: 4px;
        }
        .question-analysis {
            margin: 10px 0;
            padding: 8px;
            background-color: #fffbe6;
            border-left: 3px solid #faad14;
            border-radius: 4px;
        }
        .answer-status {
            display: inline-block;
            padding: 3px 10px;
            border-radius: 4px;
            font-size: 12px;
            font-weight: bold;
            margin-right: 10px;
        }
        .status-correct {
            background: #1ab394;
            color: white;
        }
        .status-incorrect {
            background: #ed5565;
            color: white;
        }
        .summary-info {
            display: flex;
            justify-content: space-around;
            text-align: center;
            padding: 20px;
            background: #f8f9fa;
            border-radius: 8px;
            margin-bottom: 20px;
        }
        .summary-item {
            flex: 1;
        }
        .summary-value {
            font-size: 24px;
            font-weight: bold;
            color: #1ab394;
        }
        .summary-label {
            font-size: 14px;
            color: #666;
        }
        .fill-blank-answer {
            display: inline-block;
            min-width: 100px;
            padding: 2px 8px;
            margin: 0 5px;
            border-bottom: 1px dashed #333;
            text-align: center;
        }
    </style>
</head>
<body class="gray-bg">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12">
                <div class="summary-info">
                    <div class="summary-item">
                        <div class="summary-value" th:text="${examRecord.score}">85</div>
                        <div class="summary-label">得分</div>
                    </div>
                    <div class="summary-item">
                        <div class="summary-value" th:text="${examRecord.totalQuestion}">20</div>
                        <div class="summary-label">总题数</div>
                    </div>
                    <div class="summary-item">
                        <div class="summary-value" th:text="${examRecord.correctQuestion}">17</div>
                        <div class="summary-label">正确题数</div>
                    </div>
                    <div class="summary-item">
                        <div class="summary-value" th:text="${examRecord.wrongQuestion}">3</div>
                        <div class="summary-label">错误题数</div>
                    </div>
                </div>
                
                <div class="detail-card">
                    <div class="card-header bg-primary text-white">
                        <i class="fa fa-list"></i> 答题详情
                    </div>
                    <div class="card-body">
                        <div class="question-item" th:each="detail,stat : ${examDetails}">
                            <div class="question-title">
                                <span th:text="${stat.index + 1}">1</span>. 
                                <span th:text="${detail.question.questionName}">题目内容</span>
                                <span th:if="${detail.question.questionType == 1}">（单选题）</span>
                                <span th:if="${detail.question.questionType == 2}">（多选题）</span>
                                <span th:if="${detail.question.questionType == 3}">（判断题）</span>
                                <span th:if="${detail.question.questionType == 4}">（填空题）</span>
                            </div>
                            
                            <!-- 选择题 -->
                            <div th:if="${detail.question.questionType == 1 || detail.question.questionType == 2 || detail.question.questionType == 3}" class="question-options">
                                <div class="option-item" 
                                     th:classappend="${(detail.userAnswer != null and (detail.question.questionType == 1 or detail.question.questionType == 3) and #strings.contains(detail.userAnswer, 'A')) or 
                                                    (detail.userAnswer != null and detail.question.questionType == 2 and #strings.contains(detail.userAnswer, 'A')) ? 'selected' : ''} +
                                                    ${(detail.question.correctAnswer != null and #strings.contains(detail.question.correctAnswer, 'A')) ? 'correct' : ''}">
                                    A. <span th:text="${detail.question.optionA}"></span>
                                </div>
                                <div class="option-item" 
                                     th:classappend="${(detail.userAnswer != null and (detail.question.questionType == 1 or detail.question.questionType == 3) and #strings.contains(detail.userAnswer, 'B')) or 
                                                    (detail.userAnswer != null and detail.question.questionType == 2 and #strings.contains(detail.userAnswer, 'B')) ? 'selected' : ''} +
                                                    ${(detail.question.correctAnswer != null and #strings.contains(detail.question.correctAnswer, 'B')) ? 'correct' : ''}">
                                    B. <span th:text="${detail.question.optionB}"></span>
                                </div>
                                <div class="option-item" 
                                     th:classappend="${(detail.userAnswer != null and (detail.question.questionType == 1 or detail.question.questionType == 3) and #strings.contains(detail.userAnswer, 'C')) or 
                                                    (detail.userAnswer != null and detail.question.questionType == 2 and #strings.contains(detail.userAnswer, 'C')) ? 'selected' : ''} +
                                                    ${(detail.question.correctAnswer != null and #strings.contains(detail.question.correctAnswer, 'C')) ? 'correct' : ''}">
                                    C. <span th:text="${detail.question.optionC}"></span>
                                </div>
                                <div class="option-item" 
                                     th:classappend="${(detail.userAnswer != null and (detail.question.questionType == 1 or detail.question.questionType == 3) and #strings.contains(detail.userAnswer, 'D')) or 
                                                    (detail.userAnswer != null and detail.question.questionType == 2 and #strings.contains(detail.userAnswer, 'D')) ? 'selected' : ''} +
                                                    ${(detail.question.correctAnswer != null and #strings.contains(detail.question.correctAnswer, 'D')) ? 'correct' : ''}">
                                    D. <span th:text="${detail.question.optionD}"></span>
                                </div>
                            </div>
                            
                            <!-- 填空题 -->
                            <div th:if="${detail.question.questionType == 4}">
                                <div class="user-answer">
                                    <strong>您的答案：</strong>
                                    <span th:if="${detail.userAnswer != null}" th:text="${detail.userAnswer}">用户答案</span>
                                    <span th:if="${detail.userAnswer == null}">未作答</span>
                                </div>
                                
                                <div class="correct-answer">
                                    <strong>参考答案：</strong>
                                    <span th:text="${detail.question.correctAnswer}">正确答案</span>
                                </div>
                            </div>
                            
                            <!-- 选择题的答案显示 -->
                            <div th:if="${detail.question.questionType == 1 || detail.question.questionType == 2 || detail.question.questionType == 3}">
                                <div class="user-answer">
                                    <strong>您的答案：</strong>
                                    <span th:if="${detail.userAnswer != null}" th:text="${detail.userAnswer}">用户答案</span>
                                    <span th:if="${detail.userAnswer == null}">未作答</span>
                                </div>
                                
                                <div class="correct-answer">
                                    <strong>正确答案：</strong>
                                    <span th:text="${detail.question.correctAnswer}">正确答案</span>
                                </div>
                            </div>
                            
                            <div th:if="${detail.question.analysis != null and detail.question.analysis != ''}" class="question-analysis">
                                <strong>解析：</strong>
                                <span th:text="${detail.question.analysis}">题目解析</span>
                            </div>
                            
                            <div>
                                <span class="answer-status" th:classappend="${detail.isCorrect == 1 ? 'status-correct' : 'status-incorrect'}">
                                    <span th:if="${detail.isCorrect == 1}">正确</span>
                                    <span th:if="${detail.isCorrect == 0}">错误</span>
                                </span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <th:block th:include="include :: footer" />
    
    <script type="text/javascript">
        $(function() {
            // 页面加载完成后执行
        });
    </script>
</body>
</html>